<?php

namespace app\client\admin;

class C_category
{
    /**
     * 创建资源
     * @param string $paramObj
     */
    public function store($paramObj=""){
        $messages=array();
        $messages["name.require"]="请输入名称";
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj->messages=$messages;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("S_Admin_category")->store($paramsObj);
        if($checkResult["error_no"]==0){
            $result=$checkResult["result"];
            if($result['id']){
                $paramsObj=paramsObj();
                $paramsObj->params=array(
                    "id"=>$result['id'],
                );
                $tmp=app("S_Admin_category")->updateRowLinkurl($paramsObj);
                if($tmp["error_no"]){
                    recordErrorLog($tmp); //记录错误信息
                }
                $paramsObj=paramsObj();
                $paramsObj->params=array(
                    "dataType"=>$result['dataType'],
                    "dataId"=>$result['dataId'],
                );
                $tmp=app("L_Common_caches")->updateCategory($paramsObj);
                if($tmp["error_no"]){
                    recordErrorLog($tmp); //记录错误信息
                }
            }
            return apiResult(true,"success",0,$result,$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }

    /**
     * 所有数据
     * @param string $paramObj
     */
    public function allData($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj->params=array(
            "field"=>"id,name,pid",
        );
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("S_Admin_category")->allData($paramsObj);
        if($checkResult["error_no"]==0){
            $result=$checkResult["result"];
            return apiResult(true,"success",0,$result,$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }

    /**
     * 更新资源
     * @param string $paramObj
     */
    public function update($paramObj=""){
        $messages=array();
        $messages["name.require"]="请输入名称";
        $messages["catDir.require"]="请输入分类目录";
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj->messages=$messages;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("S_Admin_category")->update($paramsObj);
        if($checkResult["error_no"]==0){
            $result=$checkResult["result"];
            if($result['id']){
                $paramsObj=paramsObj();
                $paramsObj->params=array(
                    "id"=>$result['id'],
                );
                $tmp=app("S_Admin_category")->updateRowLinkurl($paramsObj);
                if($tmp["error_no"]){
                    recordErrorLog($tmp); //记录错误信息
                }
                $paramsObj=paramsObj();
                $paramsObj->params=array(
                    "dataType"=>$result['dataType'],
                    "dataId"=>$result['dataId'],
                );
                $tmp=app("L_Common_caches")->updateCategory($paramsObj);
                if($tmp["error_no"]){
                    recordErrorLog($tmp); //记录错误信息
                }
            }
            return apiResult(true,"success",0,$result,$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }

    /**
     * 列表数据
     * @param string $paramObj
     */
    public function listData($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("S_Admin_category")->listData($paramsObj);
        if($checkResult["error_no"]==0){
            return apiResult(true,"success",0,$checkResult["result"],$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }

    /**
     * 详情
     * @param string $paramObj
     */
    public function info($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("S_Admin_category")->info($paramsObj);
        if($checkResult["error_no"]==0){
            return apiResult(true,"success",0,$checkResult["result"],$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }

    /**
     * 删除数据
     * @param string $paramObj
     */
    public function delete($paramObj=""){
        $paramsObj=paramsObj();
        $paramsObj->mixed=1;
        $paramsObj=blenderObject($paramsObj,$paramObj);
        $checkResult=app("S_Admin_category")->delete($paramsObj);
        if($checkResult["error_no"]==0){
            $result=$checkResult["result"];
            return apiResult(true,"success",0,$result,$checkResult["extra"]);
        }else{
            recordErrorLog($checkResult); //记录错误信息
            return apiResult(false,$checkResult["error_msg"],$checkResult["error_no"]);
        }
    }
}